<?php include('config.php') ?>
<?php
session_start();

$tbl_name='survey';
$response='0';

if(isset($_GET['surveyName'])&&isset($_GET['courseName']))
{
    $surveyName=$_GET['surveyName'];
    $courseName=$_GET['courseName'];
    $instructorID=$_SESSION['user_ID'];

    $surveyName = stripslashes($surveyName);
    $courseName = stripslashes($courseName);

    $surveyName =  mysql_real_escape_string($surveyName);
    $courseName =  mysql_real_escape_string($courseName);
    
    $sql="SELECT * FROM $tbl_name WHERE `instructor_ID`='$instructorID' AND `survey_name`='$surveyName' AND `course_name`='$courseName'";
    $result=  mysql_query($sql);
    $count=  mysql_num_rows($result);
    if ($count > 0) {//survey already exists
        $response = 1;
    }
    else {
        $sql = "INSERT INTO $tbl_name (`instructor_ID`, `survey_name`, `course_name`) VALUES ('$instructorID','$surveyName','$courseName')";
        mysql_query($sql);
        $response = $_GET['surveyName'];
    }
}
echo $response;
?>
